clear all
set more off
tempfile temp

/*

This dofile uses data from Truth and Reconciliation Comission to calculate the number of violent events by year-district cells.

District code is harmonized to match the 1993 version. See ubigeo dofiles in the "ubigeo" directory within dofiles.

Outcome: number of events (Terrorist) by district-year

*/

** PATHS
local working ../working
local ubigeo ../ubigeo

** DATA
use `working'/actos_est_new

*keep if inlist(idtipoac,"LDS","MAE","MAT","MEF")

local best = 2001
gen dd = substr(ubidist,-2,2)
gen ubigeo`best' = ubidist
replace ubigeo`best' = substr(ubigeona,1,6) if dd == "00"
destring ubigeo`best', replace

drop _merge
merge m:1 ubigeo`best' using `ubigeo'/ubigeo`best'to1993
drop ubigeo`best'
drop if _merge == 2
drop if _merge == 1
drop _merge

gen year = ano
gen month = year(fechamed)

gen events = 1
gen events_fatal = inlist(idtipoac,"LDS","MAE","MAT","MEF")
gen events_nonfatal = events - events_fatal

gen terrorists = e00 + e01 + e02
gen government = estado
e
gen terrorists_fatal = terrorists if events_fatal == 1
gen terrorists_nonfatal = terrorists if events_nonfatal == 1

gen government_fatal = government if events_fatal == 1
gen government_nonfatal = government if events_nonfatal == 1

keep if terrorists == 1

collapse (sum) events*, by(ubigeo1993 year) 

rename ubigeo1993 ubigeonac1993
rename year yearviolence

** SAVE
save `working'/violenceT, replace
